package com.tpshion.cloud.core.config;

import com.tpshion.cloud.core.interceptor.PermissionInterceptor;
import com.tpshion.cloud.core.interceptor.RequestLogInterceptor;
import com.tpshion.cloud.core.interceptor.SessionInterceptor;
import com.tpshion.cloud.core.resolver.SessionArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @Description: WebMvcConfigurer配置类
 * @Author: tpshion
 * @Date: 2020/12/6 12:16
 * @Version: 1.0
 */
@Configuration
public class CoreWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private RequestLogInterceptor requestLogInterceptor;

    @Autowired
    private SessionInterceptor sessionInterceptor;

    @Autowired
    private SessionArgumentResolver sessionArgumentResolver;

    @Autowired
    private PermissionInterceptor permissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册controller请求日志拦截器
        registry.addInterceptor(requestLogInterceptor).addPathPatterns("/**");
        // 注册session拦截器
        registry.addInterceptor(sessionInterceptor).addPathPatterns("/**");
        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        // 注册session参数解析器
        resolvers.add(sessionArgumentResolver);
    }
}
